//
//  BrandDetailsVC.m
//  phmall
//
//  Created by admin on 2017/11/29.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "SpecialDetailsVC.h"
#import "FUIImageView.h"
#import "HomeGoodsCell.h"
@interface SpecialDetailsVC ()<UICollectionViewDelegate,UICollectionViewDataSource,HomeGoodsCellDelegate >
{
    UIImageView      *seachV;
}
@property(nonatomic,strong)UICollectionView  *collectionView;
@end

@implementation SpecialDetailsVC
-(void)moreAction:(UICollectionViewCell *)cell{
    for (int i=0; i<10; i++) {
        NSIndexPath *index1 =  [NSIndexPath indexPathForItem:i inSection:0];
        HomeGoodsCell *goodsCell=(HomeGoodsCell *)[self.collectionView cellForItemAtIndexPath:index1];
        if (cell!=goodsCell) {
            [goodsCell moreViewTapAction];
        }
    }
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIBarButtonItem* rightBar=[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:Localized(@"更多")] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightBarAction)];
    
    self.navigationItem.rightBarButtonItem= rightBar;
    
    UIBarButtonItem* leftBar=[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(leftBarAction)];
    
    self.navigationItem.leftBarButtonItem=leftBar;
    
    
 
    
  
    
    [self.view addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view).with.offset(0);
    }];
    // Do any additional setup after loading the view.
}

-(void)rightBarAction{
    
}
-(void)seachTapAction{
    
}

#pragma mark collectionView代理方法

//返回section个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

//每个section的item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    //    NSMutableArray *goodsArr=self.timeArr[section];
    return 10;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(SCREEN_WIDTH, 120);
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    // 1.定义重用标识
    static NSString *headerID= @"reusableView";
   
    UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID forIndexPath:indexPath];

    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        headerView.backgroundColor=[UIColor groupTableViewBackgroundColor];
        for (UIView *view in headerView.subviews) {
            [view removeFromSuperview];
        }
        UIImageView *head=[[UIImageView alloc]init];
        head.image=[UIImage imageNamed:@"packing"];
        [headerView addSubview:head];
        [head mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.offset(0);
            make.height.offset(120);
            make.top.offset(0);
        }];
        UIView *line=[[UIView alloc]init];
        [head addSubview:line];
        line.backgroundColor=[UIColor colorWithHexString:@"#ECEBEC"];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.offset(0);
            make.height.offset(0.5);
        }];
        return headerView;
    }
    return nil;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId=@"cell";
    HomeGoodsCell *cell = (HomeGoodsCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
    //    cell.model=self.infoArr[indexPath.row];
    cell.delegate =self;
    ViewBorderRadius(cell, 10, 0, [UIColor clearColor]);
    return cell;
}

//设置每个item的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (iPhone5SE) {
        return CGSizeMake(SCREEN_WIDTH/2-15, 230);
    }else  if (iPhone6_6s) {
        return CGSizeMake(SCREEN_WIDTH/2-15, 252);
    }else  if (iPhone6Plus_6sPlus) {
        return CGSizeMake(SCREEN_WIDTH/2-15, 272);
    }else{
        return CGSizeMake(SCREEN_WIDTH/2-15, 252);
    }
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    for (int i=0; i<10; i++) {
        NSIndexPath *index1 =  [NSIndexPath indexPathForItem:i inSection:0];
        HomeGoodsCell *cell =  (HomeGoodsCell *)[_collectionView cellForItemAtIndexPath:index1];
        [cell moreViewTapAction];
    }
    //    self.hidesBottomBarWhenPushed=YES;
    //    CommodityDetailsVC *deta=[[CommodityDetailsVC alloc] init];
    //    [self.navigationController pushViewController:deta animated:YES];
    //    self.hidesBottomBarWhenPushed=NO;
}
//设置每个item水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}
//设置每个item垂直间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    for (int i=0; i<10; i++) {
        NSIndexPath *index1 =  [NSIndexPath indexPathForItem:i inSection:0];
        HomeGoodsCell *cell =  (HomeGoodsCell *)[_collectionView cellForItemAtIndexPath:index1];
        [cell moreViewTapAction];
    }
}
-(UICollectionView *)collectionView{
    if (!_collectionView) {
        //1.初始化layout
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        //设置collectionView滚动方向
        //    [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        //2.初始化collectionView
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
        
        //3.注册collectionViewCell
        //注意，此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致 均为 cellId
        [_collectionView registerClass:[HomeGoodsCell class] forCellWithReuseIdentifier:@"cell"];
        
        _collectionView.showsVerticalScrollIndicator=NO;
        //注册headerView  此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致  均为reusableView
        [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reusableView"];
        //4.设置代理
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    }
    return _collectionView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

